package com.tanggh.action;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.tanggh.entity.User;
import com.tanggh.service.UserService;

public class RegisterAction extends GenericAction {
	private static final long serialVersionUID = 1L;
	
	@Autowired
	private UserService userService;
	private User user = new User();

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}



	@Override
	public String execute() throws Exception {
		System.out.println(getString("name"));
//		User user = new User();
//		user.setUserName("tanggaohong");
//		user.setPassword("aaaaaa");
//		user.setCompanyName("地产公司");
//		user.setMobilePhone("15966669999");
//		user.setQq("63419666");
//		user.setUserType(1);
		user.setRegisterDate(new Timestamp(new Date().getTime()));
		user.setLatestLoginDate(new Timestamp(new Date().getTime()));
		user.setLatestLoginIp(getIP());
		
		userService.save(user);
		try {
			List<User> list = userService.listAll();
			for(User u: list) {
				System.out.println("U:"+u.getEmail());
			}
			System.out.println("userName:"+user.getEmail());
			System.out.println("ok");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
}
